package org.linlinjava.litemall.admin.controller;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.linlinjava.litemall.admin.beans.annotation.LogAnno;
import org.linlinjava.litemall.admin.beans.annotation.LoginAdminId;
import org.linlinjava.litemall.admin.beans.annotation.LoginAdminShopId;
import org.linlinjava.litemall.admin.errorcode.ErrorCodeConstants;
import org.linlinjava.litemall.admin.service.AdminHQMerchandiseService;
import org.linlinjava.litemall.admin.vo.hqmerchandise.HQListReqVO;
import org.linlinjava.litemall.admin.vo.hqmerchandise.HQReviewListReqVO;
import org.linlinjava.litemall.admin.vo.hqmerchandise.ShopReviewFormReqVO;
import org.linlinjava.litemall.admin.vo.merchandise.MerchandiseImportExcelVO;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.core.util.excel.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import static org.linlinjava.litemall.core.exception.util.ServiceExceptionUtil.exception;

@RestController
@RequestMapping("/admin/hq")
@Validated
public class AdminHQMerchandiseController {

    @Autowired
    private AdminHQMerchandiseService adminHQMerchandiseService;

    @LogAnno
    @ApiOperation("总部原料-描述列表总值")
    @PostMapping("summary")
    public ResponseUtil.Response hQMaterialSummary(){
        return adminHQMerchandiseService.hQMaterialSummary();
    }

    @LogAnno
    @ApiOperation("总部原料-列表")
    @PostMapping("list")
    public ResponseUtil.Response hqList(@RequestBody HQListReqVO reqVO){
        return adminHQMerchandiseService.hqList(reqVO);
    }

    @LogAnno
    @ApiOperation("总部原料导入记录-列表")
    @PostMapping("import-log-list")
    public ResponseUtil.Response hqImportLogList(@RequestBody HQListReqVO reqVO){
        return adminHQMerchandiseService.hqImportLogList(reqVO);
    }

    @LogAnno
    @ApiOperation("总部原料导入-列表")
    @PostMapping("import-list")
    public ResponseUtil.Response hqImportList(@RequestBody HQListReqVO reqVO){
        return adminHQMerchandiseService.hqImportList(reqVO);
    }

    @PostMapping("/import")
    @ApiOperation("导入总部原料")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file",  required = true),
            @ApiImplicitParam(name = "shopId", example = "true")
    })
    public Object importExcel(@RequestParam("file") MultipartFile file, @LoginAdminId Integer adminId) {
        try {
            List<MerchandiseImportExcelVO> list = ExcelUtils.read(file, MerchandiseImportExcelVO.class);
            return adminHQMerchandiseService.hqImportMerchandiseList(file,list, adminId);
        }catch (Exception e){
            throw exception(ErrorCodeConstants.MERCHANDISE_IMPORT_DATA_FORMAT_ERROR);
        }
    }


    @LogAnno
    @ApiOperation("门店原料申请-表单")
    @PostMapping("shop-review")
    public ResponseUtil.Response shopReview(@RequestBody ShopReviewFormReqVO reqVO, @LoginAdminShopId Integer shopId,@LoginAdminId Integer adminId){
        return adminHQMerchandiseService.shopReview(reqVO,shopId,adminId);
    }


    @LogAnno
    @ApiOperation("门店原料申请审批记录-列表")
    @PostMapping("hq-review-list")
    public ResponseUtil.Response hqMaterialApplicationReviewList(@RequestBody HQReviewListReqVO reqVO){
        return adminHQMerchandiseService.hqMaterialApplicationReviewList(reqVO);
    }

    @LogAnno
    @ApiOperation("门店原料申请审批记录详情-列表")
    @PostMapping("hq-review-detail-list")
    public ResponseUtil.Response hqMaterialApplicationReviewDetailList(@RequestBody HQReviewListReqVO reqVO){
        return adminHQMerchandiseService.hqMaterialApplicationReviewDetailList(reqVO);
    }

    @LogAnno
    @ApiOperation("门店原料申请审批记录删除")
    @GetMapping("hq-review-delete")
    public ResponseUtil.Response hqReviewDelete(@RequestParam("id") Integer id){
        return adminHQMerchandiseService.hqReviewDelete(id);
    }

    @LogAnno
    @ApiOperation("门店原料申请审批")
    @GetMapping("hq-review")
    public ResponseUtil.Response hqMaterialReviewExecutor(@RequestParam("id") Integer id,@RequestParam("status") Integer status){
        return adminHQMerchandiseService.hqMaterialReviewExecutor(id,status);
    }



}
